package com.example.user.controller.admin;

import com.example.common.response.PageResponse;
import com.example.common.response.R;
import com.example.user.request.AddressListRequest;
import com.example.user.response.AddressResponse;
import com.example.user.service.AddressService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.user.request.AddressRequest;
import java.util.List;

@RestController
@RequestMapping("admin/address")
public class AddressAdminController {
    @Autowired
    AddressService addressService;

    @GetMapping("list")
    public R<PageResponse<AddressResponse>> list(@Valid AddressListRequest request) {
        PageResponse<AddressResponse> list = addressService.list(request);
        return R.ok(list);
    }
    @PostMapping("save")
    public R<Object> save(@Valid @RequestBody AddressRequest request) {
        addressService.save(request);
        return R.ok();
    }

    @DeleteMapping("delete")
    public R<Integer> delete(@RequestBody List<Long> ids) {
        int result = addressService.deleteBatch(ids);
        return R.ok(result);
    }
}
